package com.dhy.maker.generator.file;

import com.dhy.maker.model.DataModel;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.IOException;

/**
 * 核心生成器
 */
public class FileGenerator {

    /**
     * 生成
     * @param model 数据模型
     * @throws TemplateException
     * @throws IOException
     */
    public static void doGenerate(Object model) throws TemplateException, IOException {

        String inputRootPath = "D:\\_sh\\WorkSpace\\idea_project\\generator\\generator-maker\\generated";
        String outputRootPath = "D:\\_sh\\WorkSpace\\idea_project\\generator\\generator-maker\\generated";

        String inputPath;
        String outputPath;

        inputPath = new File(inputRootPath,"src/com/dhy/acm/MainTemplate.java.ftl").getCanonicalPath();
        outputPath = new File(outputRootPath,"src/com/dhy/acm/MainTemplate.java").getCanonicalPath();
        DynamicFileGenerator.doGenerate(inputPath,outputPath,model);

        inputPath = new File(inputRootPath,".gitignore").getCanonicalPath();
        outputPath = new File(outputRootPath,".gitignore").getCanonicalPath();
        StaticFileGenerator.copyFilesByHutool(inputPath,outputPath);

        inputPath = new File(inputRootPath,"README.md").getCanonicalPath();
        outputPath = new File(outputRootPath,"README.md").getCanonicalPath();
        StaticFileGenerator.copyFilesByHutool(inputPath,outputPath);

    }
}
